﻿using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

namespace UnityEditor.UI
{
    public class UIComponentMenuItemEditor : ScriptableObject
    {
   
        [MenuItem("GameObject/UI/DynamicImage", false)]
        static public void AddUIDynamicImage(MenuCommand menuCommand)
        {
            var go = Resources.Load<DynamicImage>("DynamicImage");
            if (Selection.activeGameObject)
                go = GameObject.Instantiate(go, Selection.activeGameObject.transform);
            else
            {
                var canvas = GameObject.FindObjectOfType<Canvas>();
                if(canvas)
                    go = GameObject.Instantiate(go,canvas.transform);
            }
            go.rectTransform.anchoredPosition = Vector3.zero;
            go.name = "DynamicImage";
        }
        [MenuItem("GameObject/UI/DynamicRawImage", false)]
        static public void AddUIDynamicRawImage(MenuCommand menuCommand)
        {
            var go = Resources.Load<DynamicRawImage>("DynamicRawImage");
            if (Selection.activeGameObject)
                go = GameObject.Instantiate(go, Selection.activeGameObject.transform);
            else
            {
                var canvas = GameObject.FindObjectOfType<Canvas>();
                if(canvas)
                    go = GameObject.Instantiate(go,canvas.transform);
            }
            go.rectTransform.anchoredPosition = Vector3.zero;
            go.name = "DynamicRawImage";
        
        }
    }
}
